package crs.web.conversores;

import java.beans.PropertyEditorSupport;
import java.util.Locale;

import org.springframework.context.MessageSource;


/** 
 * ConversorLongBlank
 * @author EX90004
 * Cambia el valor de la variable Long a blanco al crear la view y de blanco a cero al retornar al cliente
 *
 */

public class ConversorBooleanString extends PropertyEditorSupport {

	private Locale locale;
	private MessageSource resource;
	
	public ConversorBooleanString(Locale locale, MessageSource resource) {
		this.locale = locale;
		this.resource = resource;
		super.setValue("");
	}

	
	public String getAsText() {
		
		if (super.getValue()==null){
			return "";
		}
		
		if ((Boolean)super.getValue()){
			return  resource.getMessage("boo.si", null, locale);
		}else{
			return  resource.getMessage("boo.no", null, locale);
		}
		
	}

	
	public void setAsText(String text) {
//		//Realizar conversión de String a Object
		if ("".equals(text)){
			super.setValue("0");
		}else{
			super.setValue(text);
		}
	}

}
